<template>
    <div class="supplement">
        <!-- 输入车牌组件 -->
        <CarKey ref="chooseCarNo" @getCarNo="getCarNo"></CarKey>
        <!-- 时间地点 -->
        <div class="info-sec" style="padding: 0.2rem 0 0;">
            <div class="info-rows">
                <div class="sup-text">上报时间</div>
                <input class="time" type="text" onfocus="this.blur()" unselectable="on" readonly="readonly" v-model="accidentInfo.accidentCreateDateStr">
            </div>
            <div class="info-rows">
                <div class="add-border-top">
                    <div class="sup-text">上报地点</div>
                    <input class="time" type="text" onfocus="this.blur()" unselectable="on" readonly="readonly" v-model="accidentAdress">
                </div>
            </div>
        </div>
        <!-- 证件上传 -->
        <div>
            <p class="f012 setWidth">上传本人证件</p>
            <input class="hideFun" type="text"><!--  用于证件上传  -->
            <div class="upPapers">
                <div @click="startUpload(index,1,value)" class="upPapersFunSec" v-for="(value,index) in picList" :key="index">
                    <span @click="deleteImg(value)" class="delete" v-show="!!value.uploadImg"></span>
                    <input :id="'cardFile'+index" accept="image/*" type="file" @change="addImg(value,1)" style="display:none">
                    <img :src="value.uploadImg||value.imgUrl" alt="">
                    <p>{{value.text}}</p>
                </div>
            </div>
        </div>
        <!-- 本方车辆信息 -->
        <p class="f012 setWidth">本方车辆信息</p>
        <div class="info-sec">
            <div class="info-rows">
                <div class="sup-text">姓名</div>
                <input class="infoItems" placeholder="请输入姓名" type="text" onfocus="this.readOnly&&this.blur()" unselectable="on" readonly v-model="params.driverName">
            </div>
            <div class="info-rows">                
                <div class="add-border-top">                    
                    <div class="sup-text">手机号码</div>
                    <input class="infoItems" placeholder="请输入手机号" maxlength="11" type="text" onfocus="this.readOnly&&this.blur()" unselectable="on" readonly v-model="params.mobile">
                </div>
            </div>
            <div class="info-rows">
                <div class="add-border-top">
                    <div class="sup-text">驾驶证号</div>
                    <input class="infoItems" placeholder="请输入驾驶证号" maxlength="100" v-model="params.driverNo" type="text">
                </div>
            </div>
            <div class="info-rows">
                <div class="add-border-top">
                    <div class="sup-text">车辆类型</div>
                    <div class="WrapFunSec infoItems">
                        <input type="text" onfocus="this.blur()" placeholder="请选择车辆类型" unselectable="on" readonly="readonly" class="flex_1" v-model="params.carType" @click="openBotttomSheet2">
                        <span></span>

                        <!-- 车辆类型弹窗选择框 -->
                         <mu-bottom-sheet :open.sync="open2">
                            <div class="picker-top"><button @click="cancel(2)">取消</button><button @click="confirmCarType(1)">确认</button></div>
                            <div class="demo-picker-container">
                                <mu-slide-picker :slots="carTySlots"  @change="addCarChange" :values="s_carType"></mu-slide-picker>
                            </div>
                        </mu-bottom-sheet>
                    </div>
                </div>
            </div>
            <div class="info-rows">
                <div class="add-border-top">
                    <div class="sup-text">车牌号</div>
                    <input class="infoItems" placeholder="请输入车牌号" @click="chooseCarNo(1)" onfocus="this.blur()" unselectable="on" readonly="readonly" type="text" v-model="params.carNo">
                </div>
            </div>
            <div class="info-rows">
                <div class="add-border-top">
                    <div class="sup-text">保险公司</div>
                    <div class="WrapFunSec infoItems">
                        <input type="text" onfocus="this.blur()" placeholder="请选择保险公司" unselectable="on" readonly="readonly" class="flex_1" @click="openBotttomSheet" v-model="params.insuranceNo">
                        <span></span>

                        <!-- 公司弹窗选择框 -->
                         <mu-bottom-sheet :open.sync="open1">
                            <div class="picker-top"><button @click="cancel(1)">取消</button><button @click="confirm(1)">确认</button></div>
                            <div class="demo-picker-container">
                                <mu-slide-picker :slots="addressSlots"  @change="addressChange" :values="s_address"></mu-slide-picker>
                            </div>
                        </mu-bottom-sheet>
                    </div>
                </div>
            </div>
            <div class="info-rows">
                <div class="add-border-top">
                    <div class="sup-text">保单号码</div>
                    <input maxlength="100" class="infoItems" placeholder="请输入保单号" type="text" v-model="params.policyNo">
                </div>
            </div>
        </div>
        <!--S 对方车辆信息 -->
        <!-- 证件上传 -->
        <div class="othersideInfo" v-if="othersideFlag">
            <p class="f012 setWidth">上传对方证件</p>
            <input class="hideFun" type="text"><!--  用于证件上传  -->
            <div class="upPapers">
                <div @click="startUpload(index,2,value)" class="upPapersFunSec" v-for="(value,index) in picList2" :key="index">
                    <span @click="deleteImg(value)" class="delete" v-show="!!value.uploadImg"></span>
                    <input :id="'cardFile2'+index" accept="image/*" type="file" @change="addImg(value,2)" style="display:none">
                    <img :src="value.uploadImg||value.imgUrl" alt="">
                    <p>{{value.text}}</p>
                </div>
            </div>
            <p class="f012 setWidth">对方车辆信息</p>
            <div class="info-sec">
                <div class="info-rows">
                    <div class="sup-text">姓名</div>
                    <input placeholder="请输入姓名" :readonly="!acState" onfocus="this.readOnly&&this.blur()" unselectable="on" class="infoItems" type="text" v-model="params2.driverName">
                </div>
                <div class="info-rows">                
                    <div class="add-border-top">                    
                        <div class="sup-text">手机号码</div>
                        <input  placeholder="请输入手机号" :readonly="!acState" onfocus="this.readOnly&&this.blur()" unselectable="on" maxlength="11" class="infoItems" type="tel" v-model="params2.mobile">
                    </div>
                </div>
                <div class="info-rows">
                    <div class="add-border-top">
                        <div class="sup-text">驾驶证号</div>
                        <input placeholder="请输入驾驶证号" class="infoItems" v-model="params2.driverNo" type="text">
                    </div>
                </div>
                <div class="info-rows">
                    <div class="add-border-top">
                        <div class="sup-text">车辆类型</div>
                        <div class="WrapFunSec infoItems">
                            <input type="text" placeholder="请选择车辆类型" onfocus="this.blur()" unselectable="on" readonly="readonly" class="flex_1" v-model="params2.carType" @click="openBotttomSheet3">
                            <span></span>

                            <!-- 车辆类型弹窗选择框 -->
                            <mu-bottom-sheet :open.sync="open3">
                                <div class="picker-top"><button @click="cancel(3)">取消</button><button @click="confirmCarType(2)">确认</button></div>
                                <div class="demo-picker-container">
                                    <mu-slide-picker :slots="carTySlots"  @change="addCarChange2" :values="s_carType2"></mu-slide-picker>
                                </div>
                            </mu-bottom-sheet>
                        </div>
                    </div>
                </div>
                <div class="info-rows">
                    <div class="add-border-top">
                        <div class="sup-text">车牌号</div>
                        <input class="infoItems" placeholder="请输入车牌号" @click="chooseCarNo(2)" onfocus="this.blur()" unselectable="on" type="text" v-model="params2.carNo">
                    </div>
                </div>
                <div class="info-rows">
                    <div class="add-border-top">
                        <div class="sup-text">保险公司</div>
                        <div class="WrapFunSec infoItems">
                            <input type="text" placeholder="请选择保险公司" onfocus="this.blur()" unselectable="on" class="flex_1" readonly="readonly" @click="openBotttomSheet4" v-model="params2.insuranceNo">
                            <span></span>

                            <!-- 保险公司弹窗选择框 -->
                            <mu-bottom-sheet :open.sync="open4">
                                <div class="picker-top"><button @click="cancel(4)">取消</button><button @click="confirm(2)">确认</button></div>
                                <div class="demo-picker-container">
                                    <mu-slide-picker :slots="addressSlots"  @change="addressChange2" :values="s_address2"></mu-slide-picker>
                                </div>
                            </mu-bottom-sheet>
                        </div>
                    </div>
                </div>
                <div class="info-rows">
                    <div class="add-border-top">
                        <div class="sup-text">保单号码</div>
                        <input maxlength="100" placeholder="请输入保单号" class="infoItems" type="text" v-model="params2.policyNo">
                    </div>
                </div>
            </div>
        </div>
        <!--E 对方车辆信息 -->
        <!-- 按钮 -->
        <div class="btnSec">
            <mu-button @click="saveCarInfo" class="submit" color="#6794F5" full-width>提交</mu-button>
        </div>
    </div>
</template>

<script>
import { http } from "utils/request.js";
import {isIos} from '../../config/env.js';
import CarKey from '../../components/carKey/carKey';
import {getOCRResult, getImgToken, upLoadImg, compressImg, setStorage} from "utils/commonUtil.js";
import api from "../../api/index.js";
export default {
  data() {
    return {
      open1: false,
      open2: false,
      open3: false,
      open4: false,
      othersideFlag: false, //对方填写信息显示
      isAllAgree: false,
      loading: "",
      choosePer:"",  //选择车牌的人 1 -a  2-b
      AIsAgree: true,
      accidentState: "", //定责状态 1-两次定责失败  2-代表a不同意  。。。
      fromPage:"",
      imgList:[], //图片列表
      insuranceNo: '', // 全责保险公司
      allState:{
        person:"",
        person2:""
      },
      s_carType: ["小型汽车"],
      s_carType2: ["小型汽车"],
      carTySlots: [],
      s_address: ["中国平安财产保险股份有限公司"],
      s_address2: ["中国平安财产保险股份有限公司"],
      addressSlots: [],
      carTyList: [], //车辆类型
      insuranceCompanyList: [], //保险公司
      carInfo: {},
      accidentInfo: {},
      params: { //本人信息 
        //提交到后台的数据
        carId: "",
        accidentNo: "",
        driverName: "",
        driverNo: "",
        carNo: "",
        mobile: "",
        insuranceNo: "",  //保险公司
        policyNo: "",   // 保险单号
        drivingNo: "",
        carType: "",
        dutyPercent: ""
      },
      params2: { //乙方信息
        //提交到后台的数据
        carId: "",
        accidentNo: "",
        driverName: "",
        driverNo: "",
        carNo: "",
        mobile: "",
        insuranceNo: "",
        policyNo: "",
        drivingNo: "",
        carType: "",
        dutyPercent: ""
      },
      picList: [
        {
          index: 0,
          defaultImg: require("../../assets/img/papers-js.png"),
          uploadImg: "",
          imgUrl: require("../../assets/img/papers-js.png"),
          text: "请上传驾驶证",
          key:"",
          type: 8
        },
        {
          index: 1,
          defaultImg: require("../../assets/img/papers-xs.png"),
          uploadImg: "",
          imgUrl: require("../../assets/img/papers-xs.png"),
          text: "请上传行驶证",
          key:"",
          type: 9
        }
      ],
      picList2: [
        {
          index: 0,
          defaultImg: require("../../assets/img/papers-js.png"),
          uploadImg: "",
          imgUrl: require("../../assets/img/papers-js.png"),
          text: "请上传驾驶证",
          key:"",
          type: 8
        },
        {
          index: 1,
          defaultImg: require("../../assets/img/papers-xs.png"),
          uploadImg: "",
          imgUrl: require("../../assets/img/papers-xs.png"),
          text: "请上传行驶证",
          key:"",
          type: 9
        }
      ]
    };
  },
  watch: {
    params: {
      handler(curVal,oldVal){
        let insuranceNo = curVal.insuranceNo;
        for (var i = 0; i < this.insuranceCompanyList.length; i++) {
          if(this.insuranceCompanyList[i].name == insuranceNo) {
            curVal.policyNo = this.insuranceCompanyList[i].baoNo;
          }
        }          
      },
      deep: true, 
    },
    params2: {
       handler(curVal,oldVal){
        let insuranceNo = curVal.insuranceNo;
        for (var i = 0; i < this.insuranceCompanyList.length; i++) {
          if(this.insuranceCompanyList[i].name == insuranceNo) {
            curVal.policyNo = this.insuranceCompanyList[i].baoNo;
          }
        }          
      },
      deep: true, 
    }
  },
  created() {
    document.title = "完善信息";
    window.scrollTo(0,0);
    // 获取事故id
    const accidentNo = this.$route.query.accidentNo;
    this.params.accidentNo = accidentNo;
    this.params2.accidentNo = accidentNo;
    //查询行驶证驾驶证信息
    this.queryImgInfo();
    //查询小车类型
    this.queryCarTyp();
    //查询保险公司名
    this.queryInsuranceCompany();
  },
  components: {
    CarKey
  },
  mounted() {
			//获取页面来源
    const fromPage = this.$route.query.fromPage;
    this.fromPage = fromPage;
		switch (fromPage) {
      //两次定责失败情况
        case "accidentPic":
            this.othersideFlag = true;
            this.accidentState = "1";
            //默认取第一条数据为a方
            this.params.fromTo = "1"; //本车
            this.params2.fromTo = "0"; //b车
            break;
				case "intelligentResult":
				//显示对方填写信息
						this.othersideFlag = true;  
            break;
        case "oppositeSideInfo":
            this.othersideFlag = true;
            break;
        case "handle":
            this.othersideFlag = true;
            break;    
				default:
						break;
    }
    this.initData();
  },
  computed: {
    //具体地址  
    accidentAdress() {
      if (this.accidentInfo&&!this.accidentInfo.accidentProvince) {
        return "";
      } else {
        return (
          this.accidentInfo.accidentProvince +
          this.accidentInfo.accidentCity +
          this.accidentInfo.accidentArea +
          this.accidentInfo.accidentWhere
        );
      }
    },
    //判断如果是2次定责失败设置输入权限 1
    //判断如果a点击不同意输入权限 2
    acState() {
      if(this.accidentState=="1"||this.accidentState=="2") {
          return true;
      }else {
          return false;
      }
    }
  },
  methods: {
    //选择车牌value = 1 a方  value=2 b方
    chooseCarNo(value) {
      // 设置选中是a还是b
      this.choosePer = value;
      /** 
       * a点击不同意b方才能选车牌 intelligentResult
       * 智能定责失败选择车牌  accidentPic
      */
      if(this.fromPage=="intelligentResult"&&value==2 || this.fromPage=="accidentPic") {
        this.$refs.chooseCarNo.openKey();
      };
    },
    getCarNo(value) {
      //判断是a选择还是b选择
        const choosePer = this.choosePer;
        if(choosePer==1) {
            this.params.carNo = value;
        } else if(choosePer==2) {
            this.params2.carNo = value;
        };
        this.$refs.chooseCarNo.closeKey();
    },
    queryImgInfo() {
        http.post(api.API_QUERY_IMAGE,{
            accidentNo:this.params.accidentNo, //事件id
            type: "two"
        }).then(((res) => {
            this.imgList = res.resultObj;
        })).catch((error) =>{
            console.log(error);
        });
    },
    //删除图片
    deleteImg(data) {
        http.post(api.API_DELETE_SINGLE_IMG,{
            photoId: data.key
        }).then(((res) => {
            if(res.code=="1") {
                data.uploadImg = "";
                data.key = "";
                this.$toast.message({
                    message: '删除成功！',
                    color: '#4caf50'
                });
            };
        })).catch((error) =>{
            console.log(error);
        });
    },
    //点击上传照片
    startUpload(index,type,data) {
      if(data.uploadImg){
        return;
      };
      if(type==1) {
        document.querySelector("#cardFile"+index).click();
      }else {
        document.querySelector("#cardFile2"+index).click();
      }
    },
    //state=1 a方  state=2 b方
    addImg(data,state) {
        const params = {};
        let _event = event;
        params.timestamp = Date.now();
        const file = event.target.files[0];
        // ***********************************************************************************ruankai
        let ext = file.name.substr(file.name.lastIndexOf('.')+1);
        if(ext!='jpg' && ext!='jpeg') {
            _event.target.value = ""; //清空之前的图片
            this.$toast.message({
                  message: '请选择jpg或jpeg格式照片',
                  color: '#F57979'
              });
            return
        };
        // ***************************************************************************************
        //加载loading
        this.loading = this.$loading({
          overlayColor:"rgba(0,0,0,.6)"
        });
        compressImg(file).then((res)=>{
          params.file = res.file;
          console.log("压缩后",res.file);
          return getImgToken();
        }).then(res=>{
            params.token = res.resultObj;
            return upLoadImg(params)
        }).then(res=>{
            _event.target.value = ""; //清空之前的图片
            data.key = res.key; //保存照片的key值
            this.getImageInfo(data,res.key,state,params.file);
        }).catch((error)=>{
            console.log(error);
            this.loading.close();
        });
    },
    //查询事故信息
    initData() {
      //取电话号码
      const mobile = this.$route.query.mobile;
      //取小车id
      const carId = this.$route.query.carId;
      this.params.carId = carId;
      http.post(api.API_ACCIDENT_DETAIL, {
          accidentNo: this.params.accidentNo
        })
        .then(res => {
          if (res.code == "1") {
            const carInfo = res.resultObj.carInfoBeans;
            this.accidentInfo = res.resultObj.accidentInfoBean;
            //如果有carid 或电话
            if (carInfo.length) {
              carInfo.forEach((data,index)=>{
                  /**
                   * 填写一个人信息根据carId比较  
                   * 填写两个人信息根据fromTo比较 1本人 
                   * 从报案记录过来根据电话匹配
                   * 两次定责失败进来默认取第一条 accidentPic
                   * */
                if (carId == data.carId&&!this.othersideFlag || mobile&&mobile == data.mobile || data.fromTo=="1"&&this.othersideFlag || this.accidentState == "1"&&index==0) {
                  //如果两次定责失败取报案人的姓名、手机号作为a方的信息
                  const driverName = this.accidentState === "1"? this.accidentInfo.appliName : data.driverName;
                  const mobile = this.accidentState == "1"? this.accidentInfo.appliMobile : data.mobile;
                  //提交的参数
                  this.params.driverName = driverName;
                  this.params.driverNo = data.driverNo||"";
                  this.params.carNo = data.carNo||"";
                  this.params.mobile = mobile;
                  this.params.insuranceNo = data.insuranceNo||"";
                  this.params.policyNo = data.policyNo||"";
                  //todo  存储
                  this.params.carId = data.carId||"";
                  this.params.carType = data.carType||"";
                  this.params.dutyPercent = data.dutyPercent||'';
                  this.allState.person = data.carStatus;
                  this.initImgInfo(this.params.carId,this.picList);
                  //当前操作方的  cardId 
                  sessionStorage.setItem('carId',this.params.carId); 
                }else { //非本人
                  this.params2.driverName = data.driverName||"";
                  this.params2.driverNo = data.driverNo||"";
                  this.params2.carNo = data.carNo||"";
                  this.params2.mobile = data.mobile||"";
                  this.params2.insuranceNo = data.insuranceNo||"";
                  this.params2.policyNo = data.policyNo||"";
                  this.params2.carId = data.carId||"";
                  this.params2.carType = data.carType||"";
                  this.params2.dutyPercent = data.dutyPercent||'';
                  this.allState.person2 = data.carStatus;
                  this.initImgInfo(this.params2.carId,this.picList2);
                };
                if(data.dutyPercent == '1') {
                  this.insuranceNo = data.insuranceNo;
                }
                //判断a点了不同意状态
                if(data.fromTo=="1"&&data.carStatus=="10") {
                  this.accidentState = "2";
                }
              });
            }
            //如果双方都同意改变状态
            if(this.allState.person=="9" && this.allState.person2=="9") {
                this.isAllAgree = true;
            }
          }
        })
        .catch(error => {
          console.log(error);
        });
    },
    //遍历照片初始化页面
    initImgInfo(caId,data) {
      if(this.imgList.length) {
          data.forEach((value,index)=>{
            this.imgList.forEach((val,ind)=>{
                if(value.type==val.photoType&&caId==val.carId) {
                  value.uploadImg = val.photoUrl;
                  value.key = val.photoId;
                }
            });
          });
      }
    },
    //智能识别行驶证驾驶证
    getImageInfo(datas,key,state,file) {
      //图片类型 8 驾驶证  9-行驶证
      const type = datas.type;
      let carId;
      if(state==1) {
        carId = this.params.carId;
      }else {
        carId = this.params2.carId;
      }
      this.OCRAndSaveCard(carId,type,key,this.params.accidentNo).then((res)=>{
              this.loading.close();
              if(res.code == "0") {
                  this.$toast.message({
                      message: res.message,
                      color: '#F57979'
                  });
                  return;
              };
              datas.uploadImg = window.URL.createObjectURL(file);
              if(type=="8"){
                  const driving_license_main_number = res.resultObj.result.driving_license_main_number;
                  const name = res.resultObj.result.name;
                  if(!driving_license_main_number) {
                      this.$toast.message({
                          message: '无法识别该驾驶证',
                          color: '#F57979'
                      });
                      return;
                  };
                  if(state==1) {
                    this.params.driverNo = driving_license_main_number;
                  }else {
                    this.params2.driverNo = driving_license_main_number;
                    //两次定责失败通过驾驶证识别b方姓名+ b不同意
                    if((this.accidentState == "1"||this.accidentState == "2")&&name) this.params2.driverName = name;
                  }
              }else {
                  const vehicle_license_main_vehicle_type = res.resultObj.result.vehicle_license_main_vehicle_type;
                  //车牌号
                  const vehicle_license_main_plate_num = res.resultObj.result.vehicle_license_main_plate_num;
                  if(!vehicle_license_main_vehicle_type) {
                      this.$toast.message({
                          message: '无法识别该行驶证',
                          color: '#F57979'
                      });
                      return;
                  };
                  if(state==1) {
                    this.params.carType = vehicle_license_main_vehicle_type;
                    //两次车牌识别失败通过行驶证识别车牌
                    if(this.accidentState == "1"&&vehicle_license_main_plate_num) this.params.carNo = vehicle_license_main_plate_num;
                  }else {
                    this.params2.carType = vehicle_license_main_vehicle_type;
                    //两次车牌识别失败通过行驶证识别车牌 -- a不同意this.accidentState = "2" 
                    if((this.accidentState == "1"||this.accidentState == "2")&&vehicle_license_main_plate_num) this.params2.carNo = vehicle_license_main_plate_num;
                  }
              }
      }).catch((error)=>{
          this.loading.close();
      });
    },
    openBotttomSheet() {
      this.open1 = true;
    },
    openBotttomSheet2() {
      this.open2 = true;
    },
    openBotttomSheet3() {
      this.open3 = true;
    },
    openBotttomSheet4() {
      this.open4 = true;
    },
    cancel(val) {
      this["open"+val] = false;
    },
		//本人点击确定选择保险公司
    confirm(val) {
      if(val==1){
          this.params.insuranceNo = this.s_address[0];
					this.open1 = false;
      }else {
          this.params2.insuranceNo = this.s_address2[0];
					this.open4 = false;
      }
    },
    confirmCarType(val) {
      if(val==1){
          this.params.carType = this.s_carType[0];
					this.open2 = false;
      }else {
          this.params2.carType = this.s_carType2[0];
					this.open3 = false;
      }
    },
    //滚动选保险公司
    addressChange(value, index) {
      //选中值
      this.s_address = [value];
    //   this.params.companyName = value;
    //   this.carInfo.insuranceNo = value;
    },
    //滚动选保险公司
    addressChange2(value, index) {
      //选中值
      this.s_address2 = [value];
    },
    //选车辆类型
    addCarChange(value, index) {
      //选中值
      this.s_carType = [value];
    //   this.params.carType = value;
    //   this.carInfo.carType = value;
    },
		addCarChange2(value, index) {
			//选中值
			this.s_carType2 = [value];
		//   this.params.carType = value;
		//   this.carInfo.carType = value;
		},
    getUpLoadResult(obj) {
      const index = this.getIndex(obj.el);
    },
    //获取图片下标
    getIndex(str) {
      if (!str) return;
      return str.charAt(str.length - 1);
    },
    /** 
     * 行驶证驾驶证识别并保存
    */
    OCRAndSaveCard(carId,type,id,accidentNo) {
        return http.post(api.API_CARD_OCR_SAVE,{
            carId: carId,
            photoType: type, //车牌识别
            photoId: id,
						accidentNo:accidentNo
        });
    },
    //查询车辆类型
    /**
     *  [
     *      {
     *          name:"",
     *          code:""
     *      }
     *  ]
     *
     */
    queryCarTyp() {
      http
        .get(api.API_CAR_TYPE)
        .then(res => {
          if (res.code == "1") {
            this.carTyList = res.resultObj;
            const newArr = [];
            res.resultObj.forEach((item,index)=>{
                if(index<32) {
                  newArr.push(item.name);
                }
            });
            this.carTySlots = [
              {
                width: "100%",
                textAlign: "center",
                values: newArr
              }
            ];
          }
        })
        .catch(error => {
          console.log(error);
        });
    },
    //查询保险公司名
    queryInsuranceCompany() {
      http
        .get(api.API_INSURANCE_COMPANY)
        .then(res => {
          if (res.code == "1") {
            this.insuranceCompanyList = res.resultObj;
            const newArr = [];
            for (var item of res.resultObj) {
              newArr.push(item.name);
            }
            this.addressSlots = [
              {
                width: "100%",
                textAlign: "center",
                values: newArr
              }
            ];
          }
        })
        .catch(error => {
          console.log(error);
        });
    },
    saveCarInfo() {   //  点击底部提交按钮
      if (!this.checkFormat()) {
        return;
      }
      //如果填写双方信息才判断
      if (this.othersideFlag&&!this.checkFormat2()) {
        return;
      };
      const params = [];
      if(this.othersideFlag) {
          params.push(this.params);
          params.push(this.params2);
      }else{
          params.push(this.params);
      };

      //  本地存储保险公司名称
      if (this.othersideFlag) {
        if(this.params.dutyPercent == '1') {
          sessionStorage.setItem('insuranceNo', this.params.insuranceNo);
        } else {
          sessionStorage.setItem('insuranceNo', this.params2.insuranceNo);
        }
      } else {
        sessionStorage.setItem('insuranceNo', this.params.insuranceNo);
      };
      console.log(sessionStorage.getItem('insuranceNo'));

      http.post(api.API_SAVE_CAR_DETAIL,{
        carInfoBeans:params
      },http.CTList[0])
      .then((res)=>{
					if (res.code == "1") {
							this.$router.push({
								name:"cognizance",
								query:{
                  accidentNo:this.params.accidentNo,
                  isAllAgree:this.isAllAgree
								}
							});
					}
			});
    },
    //a方判断
    checkFormat() {
      if (!this.picList[0].uploadImg || !this.picList[1].uploadImg) {
        this.$toast.message({
          message: "请先上传证件",
          color: "#F57979"
        });
        return false;
      }

      if(this.params.driverNo=="") {
        this.$toast.message({
          message: "请填写驾驶证号",
          color: "#F57979"
        });
        return false;
      }
      if(this.params.carType=="") {
        this.$toast.message({
          message: "请选择车辆类型",
          color: "#F57979"
        });
        return false;
      }
      if(this.params.policyNo=="") {
        this.$toast.message({
          message: "请输入保单号",
          color: "#F57979"
        });
        return false;
      }
      if(this.params.insuranceNo=="") {
        this.$toast.message({
          message: "请选择保险公司",
          color: "#F57979"
        });
        return false;
      }
      return true;
    },
    //b方判断
    checkFormat2() {
      if (!this.picList2[0].uploadImg || !this.picList2[1].uploadImg) {
        this.$toast.message({
          message: "请先上传证件",
          color: "#F57979"
        });
        return false;
      }
      if(this.params2.driverName=="") {
        this.$toast.message({
          message: "请填写姓名",
          color: "#F57979"
        });
        return false;
      }
      if(this.params2.mobile=="") {
        this.$toast.message({
          message: "请填写手机号",
          color: "#F57979"
        });
        return false;
      }
      if(this.params2.driverNo=="") {
        this.$toast.message({
          message: "请填写驾驶证号",
          color: "#F57979"
        });
        return false;
      }
      if(this.params2.carType=="") {
        this.$toast.message({
          message: "请选择车辆类型",
          color: "#F57979"
        });
        return false;
      }
      if(this.params2.policyNo=="") {
        this.$toast.message({
          message: "请输入保单号",
          color: "#F57979"
        });
        return false;
      }
      if(this.params2.insuranceNo=="") {
        this.$toast.message({
          message: "请选择保险公司",
          color: "#F57979"
        });
        return false;
      }
      return true;
    },
  }
};
</script>

<style scoped>
.supplement {
  background-color: rgb(245, 246, 248);
  /* padding: 0.2rem 0 0; */
}
.sup-text {
  color: #3d4042;
  font-size: 0.18rem;
}
input {
  font-size: 0.16rem;
  color: #8d9093;
}
.time{
    flex: 1;
    text-align: right;
}
.f012 {
  color: #8d9093;
  font-size: 0.12rem;
}
.setWidth {
  width: 3.45rem;
  margin: 0.1rem auto;
}
.hideFun {
  width: 0rem;
  height: 0rem;
  padding: 0;
  background-color: transparent;
  border: none;
  position: absolute;
}
.upPapers {
  display: flex;
  justify-content: space-around;
  align-items: center;
  height: 1.8rem;
  background-color: #fff;
}
.upPapersFunSec {
  width: 1.65rem;
  height: 1.4rem;
  border-radius: 4px;
  position: relative;
  overflow: hidden;
  text-align: center;
}
.upPapersFunSec img {
  width: 100%;
  height: 1.16rem;
}
.upPapersFunSec p {
  width: 100%;
  line-height: 0.24rem;
  color: #fff;
  background-color: #6794f5;
}
.upPapersFunSec .delete{
  display: block;
  width: 0.24rem;
  height: 0.24rem;
  background: url(../../assets/img/delete.png) no-repeat;
  background-size: 100% 100%;
  position: absolute;
  right: 0.05rem;
  top: 0.05rem;
}
.infoItems {
  width: 2.4rem;
}
.WrapFunSec {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.WrapFunSec span {
  display: inline-block;
  width: 0.15rem;
  height: 0.15rem;
  background: url(../../assets/img/arrows.png) no-repeat;
  background-size: 100% 100%;
}
.submit {
  display: block;
  width: 3.45rem;
  height: 0.48rem;
  margin: 0.2rem auto;
  font-size: 0.18rem;
}
.info-rows {
  font-size: 0.16rem;
}
.info-rows input {
  border: none;
}
.add-border-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  height: 100%;
  border-top: 1px solid #eeeeee;
}
.picker-top {
  display: flex;
  justify-content: space-between;
}
.picker-top button {
  height: 0.4rem;
  font-size: 0.15rem;
}
.picker-top button:first-child {
  margin-left: 0.2rem;
  color: #3d4042;
  background-color: transparent;
  border: none;
}
.picker-top button:last-child {
  margin-right: 0.2rem;
  color: #6794f5;
  background-color: transparent;
  border: none;
}
.othersideInfo {
  margin-top: 0.3rem;
}
.flex_1{
    flex: 1;
}
</style>
